<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.*" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="jxl.*" %>
<%@ page import="jxl.write.*" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>密码修改</title>
</head>
<body>
<%
String stuid = request.getParameter("stuid"); 
String password1 = request.getParameter("password1"); 
String password2 = request.getParameter("password2"); 
String password3 = request.getParameter("password3"); 

File fileName = new File("D:/workplace/stuinfo.xls");
Workbook book = Workbook.getWorkbook(fileName);			 /*新建一个book对象*/ 

String []array;
array = new String[5];
int rowresult=0;   //存放取得的行数
int row=0;
String password=null;
try
{
	Sheet sheet=book.getSheet(0); 		/*获得第一个工作表对象*/	
	int rows = sheet.getRows();			/*得到总行数*/
	for(row = 1; row<rows;row++)
	{
		Cell cell = sheet.getCell(0, row);
		String str = cell.getContents();
		if(str.equals(stuid))
		{
			Cell cell1 = sheet.getCell(10, row);
			password = cell1.getContents();
			rowresult = row;
						
		}
	}
}catch(Exception e)
{
	System.out.println(e);
}


//判断初始密码是否输入正确 
if(!password.equals(password1))
{
	book.close();
%>
	<a href="stumodifypassword.jsp?stuid=<%= stuid%>">初始密码错误，请返回重新输入！</a>
<% 	
}
else
{
	if(password2.equals(stuid))
	{
		book.close();
	%>
		<a href="stumodifypassword.jsp?stuid=<%= stuid%>">密码不能与学号相同，请返回重新输入！</a>
		
	<%
	}
	
	else if(password2.length()<6)
	{
		book.close();
	%>
		<a href="stumodifypassword.jsp?stuid=<%= stuid%>">密码长度不够，请返回重新输入！</a>
		
	<%
	}
	else if(!password2.equals(password3))
	{
		book.close();
		%>
		<a href="stumodifypassword.jsp?stuid=<%= stuid%>">两次输入密码不一致，请返回重新输入！</a>
		<% 
	}
	else
	{
	WritableWorkbook workbook = Workbook.createWorkbook(new File("D:/workplace/stuinfo.xls"),book);		/*新建一个workbook对象，指向book */	
	WritableSheet sheet2 = workbook.getSheet(0);
	WritableCell cel1 = sheet2.getWritableCell(10, rowresult);
	Label l1 = (Label) cel1;
	l1.setString(password2);
	workbook.write();
	workbook.close();
	%>
	<a href="stumaininfo.jsp?stuid=<%= stuid%>">密码修改成功，请返回个人主页！</a>
	<% 	
	}
}

book.close();

%>

	
	
	


</body>
</html>